package com.itheima.controller;

import com.itheima.anno.Log;
import com.itheima.pojo.Dept;
import com.itheima.pojo.Result;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/depts")
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;

    /*
    查询部门数据
     */
    @GetMapping
    public Result list(){
        log.info("查询全部部门数据");

        //调用service查询数据
        List<Dept> deptList = deptService.list();

        return Result.success(deptList);
    }

    /*
    删除部门
     */
    @Log
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
         log.info("根据id删除部门:{}",id);
         //调用Service删除部门
        deptService.delete(id);
        return Result.success();
    }

    /*
    新增部门
     */
    @Log
    @PostMapping
    public Result add(@RequestBody Dept dept){
        deptService.add(dept);
        return Result.success();
    }

    /*
    根据Id查询部门
     */
    @GetMapping("/{id}")
    public Result select(@PathVariable Integer id){
        List<Dept> deptList = deptService.select(id);
        return Result.success(deptList);
    }
    /*
    修改部门
     */
    @Log
    @PutMapping
    public Result update(@RequestBody Dept dept){
        deptService.update(dept);
        return Result.success();
    }

    //这里进行合并测试

    //这里进行二号位测试
}
